package platform_api.Service;

import org.springframework.stereotype.Service;
import platform_api.Model.JsonMessage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Service
public class BaseService {
    /**
     * Echarts 封装
     *
     * @param category x轴
     * @param data     y轴
     * @return json 数据
     */
    static JsonMessage getJsonMessage(ArrayList<String> category, ArrayList<String> data, Object min,Object max, String columnName) {
        Map<String, Object> content = new HashMap<>();
        content.put("category", category);
        content.put("data", data);
        content.put("min", min);
        content.put("max", max);
        content.put("column", columnName);
        return new JsonMessage(200, content);
    }

    /**
     * 封装
     * @param category x轴
     * @param data y轴
     * @return json 数据
     */
    static JsonMessage getJsonMessage(ArrayList<String> category, ArrayList<String> data) {
        Map<String, Object> content = new HashMap<>();
        content.put("category", category);
        content.put("data", data);
        return new JsonMessage(200, content);
    }

    /**
     * 封装错误信息
     * @param status 状态码
     * @param message 错误信息
     * @return json 数据
     */
    static JsonMessage getJsonErrorMessage(Object status, String message) {
        Map<String, Object> content = new HashMap<>();
        content.put("errorCode", status);
        content.put("errorMessage", message);
        return new JsonMessage(-1, content);
    }
}
